<template>
  <BasicModal
    title="选择数据集"
    width="50%"
    @register="registerModal"
    @ok="handleSelect"
  >
    <BasicTable @register="registerTable" />
  </BasicModal>
</template>
<script setup lang="ts">
import { BasicModal, useModalInner } from '@/components/Modal';
import { BasicTable, useTable, TableAction } from '@/components/Table';
import { page } from '@/api/sys/dev/reportDataSetManager';
const emit = defineEmits(['select']);
const [registerModal, { closeModal }] = useModalInner(async () => {});
const [registerTable, { reload, getSelectRows }] = useTable({
  title: '列表',
  api: page,
  columns: [
    {
      title: '数据集key',
      align: 'center',
      dataIndex: 'setCode',
    },
    {
      title: '数据集名称',
      align: 'center',
      dataIndex: 'setName',
    },
    {
      title: '创建时间',
      align: 'center',
      dataIndex: 'createTime',
    },
  ],
  formConfig: {
    labelWidth: 120,
    schemas: [
      {
        field: 'setName',
        label: '数据集名称',
        component: 'Input',
        required: false,
      },
    ],
    baseColProps: { span: 12 },
  },
  rowSelection: {
    type: 'radio',
  },
  useSearchForm: true,
  pagination: true,
  bordered: true,
  showIndexColumn: false,
});
const handleSelect = () => {
  const selected = getSelectRows();
  if (selected.length) {
    emit('select', selected[0].setCode);
    closeModal();
  }
};
</script>
